package com.dareway.thread;

public class Thread_join {
    //一个线程等待另一个线程执行完成后再继续进行
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            System.out.println("线程1开始执行");
            for (int i = 0; i < 50; i ++ ) {
                System.out.println("1：" + i);
            }
            System.out.println("线程1开始执行");
        });
        Thread t2 = new Thread(()->{
            System.out.println("线程2开始执行");
            for (int i = 0; i < 50; i ++ ) {
                System.out.println("2：" + i);
                if (i == 10) {
                    try {
                        System.out.println("线程1加入到此线程");
                        t1.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            System.out.println("线程2开始执行");
        });
        t1.start();
        t2.start();
    }
}
